#ifndef __INT2HUMAN__H__
#define __INT2HUMAN__H__

#include "stdint.h"
#include "inttypes.h"
#include "stdio.h"
#include "log.h"

static inline char *int2dingchang_string_2(int html_format, int left_align, uint64_t n, char *buf, const char *tail)
{
    const char *div = html_format ? "&nbsp;" : " ";
    if (tail == NULL) tail = "";

    if (n >= 10) { sprintf(buf, "%"PRIu64"%s", n, tail); return buf; }

    if (left_align)
        sprintf(buf, "%"PRIu64"%s%s", n, tail, div);
    else
        sprintf(buf, "%s%"PRIu64"%s", div, n, tail);
    return buf;
}

static inline char *int2dingchang_string_3_noyu(int html_format, int left_align, uint64_t n, char *buf, char *danwei, const char *tail)
{
    const char *div = html_format ? "&nbsp;" : " ";

    if (left_align > 0) {
        if      (n < 10)            { if (danwei[0]) sprintf(buf, "%"PRIu64"%s%s%s", n , danwei, tail, div); else sprintf(buf, "%"PRIu64"%s%s%s", n, tail, div, div); }
        else if (n < 100)           { if (danwei[0]) sprintf(buf, "%"PRIu64"%s%s"  , n , danwei, tail     ); else sprintf(buf, "%"PRIu64"%s%s"  , n, tail, div); }
        else { sprintf(buf, "%"PRIu64"%s%s", n , danwei, tail); return buf; }
    } else {
        if      (n < 10)            { if (danwei[0]) sprintf(buf, "%s%"PRIu64"%s%s", div, n, danwei, tail); else sprintf(buf, "%s%s%"PRIu64"%s", div, div, n, tail); }
        else if (n < 100)           { if (danwei[0]) sprintf(buf, "%"PRIu64"%s%s"  ,      n, danwei, tail); else sprintf(buf, "%s%"PRIu64"%s"  , div, n, tail); }
        else { sprintf(buf, "%"PRIu64"%s%s", n , danwei, tail); return buf; }
    }
    return buf;
}

static inline char *int2dingchang_string_4_noyu(int html_format, int left_align, uint64_t n, char *buf, char *danwei, const char *tail)
{
    const char *div = html_format ? "&nbsp;" : " ";

    if (left_align > 0) {
        if      (n < 10)            { if (danwei[0]) sprintf(buf, "%"PRIu64"%s%s%s%s", n , danwei, tail, div, div); else sprintf(buf, "%"PRIu64"%s%s%s%s", n, tail, div, div, div); }
        else if (n < 100)           { if (danwei[0]) sprintf(buf, "%"PRIu64"%s%s%s"  , n , danwei, tail, div     ); else sprintf(buf, "%"PRIu64"%s%s%s"  , n, tail, div, div); }
        else if (n < 1000)          { if (danwei[0]) sprintf(buf, "%"PRIu64"%s%s"    , n , danwei, tail          ); else sprintf(buf, "%"PRIu64"%s%s"    , n, tail, div); }
        else { sprintf(buf, "%"PRIu64"%s%s", n , danwei, tail); return buf; }
    } else {
        if      (n < 10)            { if (danwei[0]) sprintf(buf, "%s%s%"PRIu64"%s%s", div, div, n, danwei, tail); else sprintf(buf, "%s%s%s%"PRIu64"%s", div, div, div, n, tail); }
        else if (n < 100)           { if (danwei[0]) sprintf(buf, "%s%"PRIu64"%s%s"  ,      div, n, danwei, tail); else sprintf(buf, "%s%s%"PRIu64"%s"  , div, div, n, tail); }
        else if (n < 1000)          { if (danwei[0]) sprintf(buf, "%"PRIu64"%s%s"    ,           n, danwei, tail); else sprintf(buf, "%s%"PRIu64"%s"    , div, n, tail); }
        else { sprintf(buf, "%"PRIu64"%s%s", n , danwei, tail); return buf; }
    }
    return buf;
}

static inline char *int2dingchang_string_6_noyu(int html_format, int left_align, uint64_t n, char *buf, char *danwei, const char *tail)
{
    const char *div = html_format ? "&nbsp;" : " ";

    if (left_align > 0) {
        if      (n < 10)            { if (danwei[0]) sprintf(buf, "%"PRIu64"%s%s%s%s%s%s", n , danwei, tail, div, div, div, div); else sprintf(buf, "%"PRIu64"%s%s%s%s%s%s%s", n, tail, div, div, div, div, div, div); }
        else if (n < 100)           { if (danwei[0]) sprintf(buf, "%"PRIu64"%s%s%s%s%s"  , n , danwei, tail, div, div, div     ); else sprintf(buf, "%"PRIu64"%s%s%s%s%s%s"  , n, tail, div, div, div, div, div); }
        else if (n < 1000)          { if (danwei[0]) sprintf(buf, "%"PRIu64"%s%s%s%s"    , n , danwei, tail, div, div          ); else sprintf(buf, "%"PRIu64"%s%s%s%s%s"    , n, tail, div, div, div, div); }
        else if (n < 10000)         { if (danwei[0]) sprintf(buf, "%"PRIu64"%s%s%s"      , n , danwei, tail, div               ); else sprintf(buf, "%"PRIu64"%s%s%s%s"      , n, tail, div, div, div); }
        else if (n < 100000)        { if (danwei[0]) sprintf(buf, "%"PRIu64"%s%s"        , n , danwei, tail                    ); else sprintf(buf, "%"PRIu64"%s%s%s"        , n, tail, div, div); }
        else { sprintf(buf, "%"PRIu64"%s%s", n , danwei, tail); }
    } else {
        if      (n < 10)            { if (danwei[0]) sprintf(buf, "%s%s%s%s%"PRIu64"%s%s", div, div, div, div, n, danwei, tail); else sprintf(buf, "%s%s%s%s%s%s%"PRIu64"%s", div, div, div, div, div, div, n, tail); }
        else if (n < 100)           { if (danwei[0]) sprintf(buf, "%s%s%s%"PRIu64"%s%s"  , div, div,      div, n, danwei, tail); else sprintf(buf, "%s%s%s%s%s%"PRIu64"%s"  , div, div, div, div, div, n, tail); }
        else if (n < 1000)          { if (danwei[0]) sprintf(buf, "%s%s%"PRIu64"%s%s"    , div, div,           n, danwei, tail); else sprintf(buf, "%s%s%s%s%"PRIu64"%s"    , div, div, div, div, n, tail); }
        else if (n < 10000)         { if (danwei[0]) sprintf(buf, "%s%"PRIu64"%s%s"      , div,                n, danwei, tail); else sprintf(buf, "%s%s%s%"PRIu64"%s"      , div, div, div, n, tail); }
        else if (n < 100000)        { if (danwei[0]) sprintf(buf, "%"PRIu64"%s%s"        ,                     n, danwei, tail); else sprintf(buf, "%s%s%"PRIu64"%s"        , div, div, n, tail); }
        else { sprintf(buf, "%"PRIu64"%s%s", n , danwei, tail); }
    }
    return buf;
}

static inline char *int2dingchang_string_7_noyu(int html_format, int left_align, uint64_t n, char *buf, char *danwei, const char *tail)
{
    const char *div = html_format ? "&nbsp;" : " ";

    if (left_align > 0) {
        if      (n < 10)            { if (danwei[0]) sprintf(buf, "%"PRIu64"%s%s%s%s%s%s%s", n , danwei, tail, div, div, div, div, div); else sprintf(buf, "%"PRIu64"%s%s%s%s%s%s%s", n, tail, div, div, div, div, div, div); }
        else if (n < 100)           { if (danwei[0]) sprintf(buf, "%"PRIu64"%s%s%s%s%s%s"  , n , danwei, tail, div, div, div, div     ); else sprintf(buf, "%"PRIu64"%s%s%s%s%s%s"  , n, tail, div, div, div, div, div); }
        else if (n < 1000)          { if (danwei[0]) sprintf(buf, "%"PRIu64"%s%s%s%s%s"    , n , danwei, tail, div, div, div          ); else sprintf(buf, "%"PRIu64"%s%s%s%s%s"    , n, tail, div, div, div, div); }
        else if (n < 10000)         { if (danwei[0]) sprintf(buf, "%"PRIu64"%s%s%s%s"      , n , danwei, tail, div, div               ); else sprintf(buf, "%"PRIu64"%s%s%s%s"      , n, tail, div, div, div); }
        else if (n < 100000)        { if (danwei[0]) sprintf(buf, "%"PRIu64"%s%s%s"        , n , danwei, tail, div                    ); else sprintf(buf, "%"PRIu64"%s%s%s"        , n, tail, div, div); }
        else if (n < 1000000)       { if (danwei[0]) sprintf(buf, "%"PRIu64"%s%s"          , n , danwei, tail                         ); else sprintf(buf, "%"PRIu64"%s%s"          , n, tail, div); }
        else { sprintf(buf, "%"PRIu64"%s%s", n , danwei, tail); }
    } else {
        if      (n < 10)            { if (danwei[0]) sprintf(buf, "%s%s%s%s%s%"PRIu64"%s%s", div, div, div, div, div, n, danwei, tail); else sprintf(buf, "%s%s%s%s%s%s%"PRIu64"%s", div, div, div, div, div, div, n, tail); }
        else if (n < 100)           { if (danwei[0]) sprintf(buf, "%s%s%s%s%"PRIu64"%s%s"  , div, div, div,      div, n, danwei, tail); else sprintf(buf, "%s%s%s%s%s%"PRIu64"%s"  , div, div, div, div, div, n, tail); }
        else if (n < 1000)          { if (danwei[0]) sprintf(buf, "%s%s%s%"PRIu64"%s%s"    , div, div, div,           n, danwei, tail); else sprintf(buf, "%s%s%s%s%"PRIu64"%s"    , div, div, div, div, n, tail); }
        else if (n < 10000)         { if (danwei[0]) sprintf(buf, "%s%s%"PRIu64"%s%s"      , div, div,                n, danwei, tail); else sprintf(buf, "%s%s%s%"PRIu64"%s"      , div, div, div, n, tail); }
        else if (n < 100000)        { if (danwei[0]) sprintf(buf, "%s%"PRIu64"%s%s"        , div,                     n, danwei, tail); else sprintf(buf, "%s%s%"PRIu64"%s"        , div, div, n, tail); }
        else if (n < 1000000)       { if (danwei[0]) sprintf(buf, "%"PRIu64"%s%s"          ,                          n, danwei, tail); else sprintf(buf, "%s%"PRIu64"%s"          , div, n, tail); }
        else { sprintf(buf, "%"PRIu64"%s%s", n , danwei, tail); }
    }
    return buf;
}

static inline char *int2dingchang_string_10_noyu(int html_format, int left_align, uint64_t n, char *buf, char *danwei, const char *tail)
{
    const char *div = html_format ? "&nbsp;" : " ";

    if (left_align > 0) {
        if      (n < 10)            { if (danwei[0]) sprintf(buf, "%"PRIu64"%s%s%s%s%s%s%s%s%s%s", n , danwei, tail, div, div, div, div, div, div, div, div); else sprintf(buf, "%"PRIu64"%s%s%s%s%s%s%s%s%s%s", n, tail, div, div, div, div, div, div, div, div, div); }
        else if (n < 100)           { if (danwei[0]) sprintf(buf, "%"PRIu64"%s%s%s%s%s%s%s%s%s"  , n , danwei, tail, div, div, div, div, div, div, div     ); else sprintf(buf, "%"PRIu64"%s%s%s%s%s%s%s%s%s"  , n, tail, div, div, div, div, div, div, div, div); }
        else if (n < 1000)          { if (danwei[0]) sprintf(buf, "%"PRIu64"%s%s%s%s%s%s%s%s"    , n , danwei, tail, div, div, div, div, div, div          ); else sprintf(buf, "%"PRIu64"%s%s%s%s%s%s%s%s"    , n, tail, div, div, div, div, div, div, div); }
        else if (n < 10000)         { if (danwei[0]) sprintf(buf, "%"PRIu64"%s%s%s%s%s%s%s"      , n , danwei, tail, div, div, div, div, div               ); else sprintf(buf, "%"PRIu64"%s%s%s%s%s%s%s"      , n, tail, div, div, div, div, div, div); }
        else if (n < 100000)        { if (danwei[0]) sprintf(buf, "%"PRIu64"%s%s%s%s%s%s"        , n , danwei, tail, div, div, div, div                    ); else sprintf(buf, "%"PRIu64"%s%s%s%s%s%s"        , n, tail, div, div, div, div, div); }
        else if (n < 1000000)       { if (danwei[0]) sprintf(buf, "%"PRIu64"%s%s%s%s%s"          , n , danwei, tail, div, div, div                         ); else sprintf(buf, "%"PRIu64"%s%s%s%s%s"          , n, tail, div, div, div, div); }
        else if (n < 10000000)      { if (danwei[0]) sprintf(buf, "%"PRIu64"%s%s%s%s"            , n , danwei, tail, div, div                              ); else sprintf(buf, "%"PRIu64"%s%s%s%s"            , n, tail, div, div, div); }
        else if (n < 100000000)     { if (danwei[0]) sprintf(buf, "%"PRIu64"%s%s%s"              , n , danwei, tail, div                                   ); else sprintf(buf, "%"PRIu64"%s%s%s"              , n, tail, div, div); }
        else if (n < 1000000000)    { if (danwei[0]) sprintf(buf, "%"PRIu64"%s%s"                , n , danwei, tail                                        ); else sprintf(buf, "%"PRIu64"%s%s"                , n, tail, div); }
        else { sprintf(buf, "%"PRIu64"%s%s", n , danwei, tail); }
    } else {
        if      (n < 10)            { if (danwei[0]) sprintf(buf, "%s%s%s%s%s%s%s%s%"PRIu64"%s%s", div, div, div, div, div, div, div, div, n, danwei, tail); else sprintf(buf, "%s%s%s%s%s%s%s%s%s%"PRIu64"%s", div, div, div, div, div, div, div, div, div, n, tail); }
        else if (n < 100)           { if (danwei[0]) sprintf(buf, "%s%s%s%s%s%s%s%"PRIu64"%s%s"  , div, div, div, div, div, div, div,      n, danwei, tail); else sprintf(buf, "%s%s%s%s%s%s%s%s%"PRIu64"%s"  , div, div, div, div, div, div, div, div, n, tail); }
        else if (n < 1000)          { if (danwei[0]) sprintf(buf, "%s%s%s%s%s%s%"PRIu64"%s%s"    , div, div, div, div, div, div,           n, danwei, tail); else sprintf(buf, "%s%s%s%s%s%s%s%"PRIu64"%s"    , div, div, div, div, div, div, div, n, tail); }
        else if (n < 10000)         { if (danwei[0]) sprintf(buf, "%s%s%s%s%s%"PRIu64"%s%s"      , div, div, div, div, div,                n, danwei, tail); else sprintf(buf, "%s%s%s%s%s%s%"PRIu64"%s"      , div, div, div, div, div, div, n, tail); }
        else if (n < 100000)        { if (danwei[0]) sprintf(buf, "%s%s%s%s%"PRIu64"%s%s"        , div, div, div, div,                     n, danwei, tail); else sprintf(buf, "%s%s%s%s%s%"PRIu64"%s"        , div, div, div, div, div, n, tail); }
        else if (n < 1000000)       { if (danwei[0]) sprintf(buf, "%s%s%s%"PRIu64"%s%s"          , div, div, div,                          n, danwei, tail); else sprintf(buf, "%s%s%s%s%"PRIu64"%s"          , div, div, div, div, n, tail); }
        else if (n < 10000000)      { if (danwei[0]) sprintf(buf, "%s%s%"PRIu64"%s%s"            , div, div,                               n, danwei, tail); else sprintf(buf, "%s%s%s%"PRIu64"%s"            , div, div, div, n, tail); }
        else if (n < 100000000)     { if (danwei[0]) sprintf(buf, "%s%"PRIu64"%s%s"              , div,                                    n, danwei, tail); else sprintf(buf, "%s%s%"PRIu64"%s"              , div, div, n, tail); }
        else if (n < 1000000000)    { if (danwei[0]) sprintf(buf, "%"PRIu64"%s%s"                ,                                         n, danwei, tail); else sprintf(buf, "%s%"PRIu64"%s"                , div, n, tail); }
        else { sprintf(buf, "%"PRIu64"%s%s", n , danwei, tail); }
    }
    return buf;
}

static inline char *int2dingchang_string_4(int html_format, int left_align, uint64_t n, uint64_t yu, char *buf, const char *tail)
{
    const char *div = html_format ? "&nbsp;" : " ";

    if (n >= 1000) { sprintf(buf, "%"PRIu64"%s", n, tail); return buf; }

    if (left_align > 0) {
        if (n < 10 && tail[0] == 0) sprintf(buf, "%"PRIu64"%s%s%s"      , n, div, div, div);
        else if (n < 10 )           sprintf(buf, "%"PRIu64".%"PRIu64"%s", n, yu, tail);
        else if (n < 100)           sprintf(buf, "%"PRIu64".%"PRIu64"%s", n, yu, tail);
        else if (n < 1000)          sprintf(buf, "%"PRIu64"%s%s"        , n, div, tail);
    } else {
        if (n < 10 && tail[0] == 0) sprintf(buf, "%s%s%s%"PRIu64          , div, div, div, n);
        else if (n < 10 )           sprintf(buf, "%s%"PRIu64".%"PRIu64"%s", div, n, yu, tail);
        else if (n < 100)           sprintf(buf, "%"PRIu64".%"PRIu64"%s"  , n, yu, tail);
        else if (n < 1000)          sprintf(buf, "%s%"PRIu64"%s"          , div, n, tail);
    }
    return buf;
}

static inline char *int2dingchang_string_5(int html_format, int left_align, uint64_t n, char *buf, const char *tail)
{
    const char *div = html_format ? "&nbsp;" : " ";

    if (n >= 10000) { sprintf(buf, "%"PRIu64"%s", n, tail); return buf; }

    if (left_align > 0) {
        if      (n < 10)            { if (tail[0]) sprintf(buf, "%"PRIu64"%s%s%s%s", n, tail, div, div, div); else sprintf(buf, "%"PRIu64"%s%s%s%s", n, div, div, div, div); }
        else if (n < 100)           { if (tail[0]) sprintf(buf, "%"PRIu64"%s%s%s"  , n, tail, div, div     ); else sprintf(buf, "%"PRIu64"%s%s%s"  , n, div, div, div); }
        else if (n < 1000)          { if (tail[0]) sprintf(buf, "%"PRIu64"%s%s"    , n, tail, div          ); else sprintf(buf, "%"PRIu64"%s%s"    , n, div, div); }
        else if (n < 10000)         { if (tail[0]) sprintf(buf, "%"PRIu64"%s"      , n, tail               ); else sprintf(buf, "%"PRIu64"%s"      , n, div); }
    } else {
        if      (n < 10)            { if (tail[0]) sprintf(buf, "%s%s%s%"PRIu64"%s", div, div, div, n, tail); else sprintf(buf, "%s%s%s%s%"PRIu64, div, div, div, div, n); }
        else if (n < 100)           { if (tail[0]) sprintf(buf, "%s%s%"PRIu64"%s"       , div, div, n, tail); else sprintf(buf, "%s%s%s%"PRIu64       , div, div, div, n); }
        else if (n < 1000)          { if (tail[0]) sprintf(buf, "%s%"PRIu64"%s"              , div, n, tail); else sprintf(buf, "%s%s%"PRIu64              , div, div, n); }
        else if (n < 10000)         { if (tail[0]) sprintf(buf, "%"PRIu64"%s"                     , n, tail); else sprintf(buf, "%s%"PRIu64                     , div, n); }
    }
    return buf;
}

static inline char *int2dingchang_string_4_yu(int html_format, int left_align, uint64_t n, uint64_t yu, char *buf, char *danwei, const char *tail)
{
    const char *div = html_format ? "&nbsp;" : " ";

    if (n >= 1000) { sprintf(buf, "%"PRIu64"%s%s", n , danwei, tail); return buf; }

    if (left_align > 0) {
        if      (n < 10)            { if (danwei[0]) sprintf(buf, "%"PRIu64".%"PRIu64"%s%s", n, yu, danwei, tail     ); else sprintf(buf, "%"PRIu64"%s%s%s%s", n, tail, div, div, div); }
        else if (n < 100)           { if (danwei[0]) sprintf(buf, "%"PRIu64"%s%s%s"        , n    , danwei, tail, div); else sprintf(buf, "%"PRIu64"%s%s%s"  , n, tail, div, div); }
        else if (n < 1000)          { if (danwei[0]) sprintf(buf, "%"PRIu64"%s%s"          , n    , danwei, tail     ); else sprintf(buf, "%"PRIu64"%s%s"    , n, tail, div); }
    } else {
        if      (n < 10)            { if (danwei[0]) sprintf(buf, "%"PRIu64".%"PRIu64"%s%s"     , n, yu, danwei, tail); else sprintf(buf, "%s%s%s%"PRIu64"%s", div, div, div, n, tail); }
        else if (n < 100)           { if (danwei[0]) sprintf(buf, "%s%"PRIu64"%s%s"        , div, n,     danwei, tail); else sprintf(buf, "%s%s%"PRIu64"%s"  , div, div, n, tail); }
        else if (n < 1000)          { if (danwei[0]) sprintf(buf, "%"PRIu64"%s%s"               , n,     danwei, tail); else sprintf(buf, "%s%"PRIu64"%s"    , div, n, tail); }
    }
    return buf;
}

static inline char *int2dingchang_string_5_yu(int html_format, int left_align, uint64_t n, uint64_t yu, uint64_t yu2, char *buf, char *danwei, const char *tail)
{
    const char *div = html_format ? "&nbsp;" : " ";

    if (n >= 10000) { sprintf(buf, "%"PRIu64"%s%s", n , danwei, tail); return buf; }

    if (left_align > 0) {
        if      (n < 10)            { if (danwei[0]) sprintf(buf, "%"PRIu64".%"PRIu64"%"PRIu64"%s%s", n, yu, yu2, danwei, tail     ); else sprintf(buf, "%"PRIu64"%s%s%s%s%s", n, div, div, div, div, tail); }
        else if (n < 100)           { if (danwei[0]) sprintf(buf, "%"PRIu64".%"PRIu64"%s%s"         , n, yu     , danwei, tail     ); else sprintf(buf, "%"PRIu64"%s%s%s%s"  , n, div, div, div, tail); }
        else if (n < 1000)          { if (danwei[0]) sprintf(buf, "%"PRIu64"%s%s%s"                 , n         , danwei, div, tail); else sprintf(buf, "%"PRIu64"%s%s%s"    , n, div, div, tail); }
        else if (n < 10000)         { if (danwei[0]) sprintf(buf, "%"PRIu64"%s%s"                   , n         , danwei, tail     ); else sprintf(buf, "%"PRIu64"%s%s"      , n, div, tail); }
    } else {
        if      (n < 10)            { if (danwei[0]) sprintf(buf, "%"PRIu64".%"PRIu64"%"PRIu64"%s%s", n, yu, yu2, danwei, tail); else sprintf(buf, "%s%s%s%s%"PRIu64"%s", div, div, div, div, n, tail); }
        else if (n < 100)           { if (danwei[0]) sprintf(buf, "%"PRIu64".%"PRIu64"%s%s"         , n, yu     , danwei, tail); else sprintf(buf, "%s%s%s%"PRIu64"%s"       , div, div, div, n, tail); }
        else if (n < 1000)          { if (danwei[0]) sprintf(buf, "%s%"PRIu64"%s%s"            ,div , n         , danwei, tail); else sprintf(buf, "%s%s%"PRIu64"%s"              , div, div, n, tail); }
        else if (n < 10000)         { if (danwei[0]) sprintf(buf, "%"PRIu64"%s%s"                   , n         , danwei, tail); else sprintf(buf, "%s%"PRIu64"%s"                     , div, n, tail); }
    }
    return buf;
}

static inline char *int2dingchang_string_6_yu(int html_format, int left_align, uint64_t n, uint64_t yu, uint64_t yu2, uint64_t yu3, char *buf, char *danwei, const char *tail)
{
    const char *div = html_format ? "&nbsp;" : " ";

    if (n >= 100000) { sprintf(buf, "%"PRIu64"%s%s", n , danwei, tail); return buf; }

    if (left_align > 0) {
        if      (n < 10)            { if (danwei[0]) sprintf(buf, "%"PRIu64".%"PRIu64"%"PRIu64"%"PRIu64"%s%s", n, yu, yu2, yu3, danwei, tail     ); else sprintf(buf, "%"PRIu64"%s%s%s%s%s%s", n, tail, div, div, div, div, div); }
        else if (n < 100)           { if (danwei[0]) sprintf(buf, "%"PRIu64".%"PRIu64"%"PRIu64"%s%s"         , n, yu, yu2     , danwei, tail     ); else sprintf(buf, "%"PRIu64"%s%s%s%s%s"  , n, tail, div, div, div, div); }
        else if (n < 1000)          { if (danwei[0]) sprintf(buf, "%"PRIu64".%"PRIu64"%s%s"                  , n, yu          , danwei, tail     ); else sprintf(buf, "%"PRIu64"%s%s%s%s"    , n, tail, div, div, div); }
        else if (n < 10000)         { if (danwei[0]) sprintf(buf, "%"PRIu64"%s%s%s"                          , n              , danwei, tail, div); else sprintf(buf, "%"PRIu64"%s%s%s"      , n, tail, div, div); }
        else if (n < 100000)        { if (danwei[0]) sprintf(buf, "%"PRIu64"%s%s"                            , n              , danwei, tail     ); else sprintf(buf, "%"PRIu64"%s%s"        , n, tail, div); }
    } else {
        if      (n < 10)            { if (danwei[0]) sprintf(buf, "%"PRIu64".%"PRIu64"%"PRIu64"%"PRIu64"%s%s", n, yu, yu2, yu3, danwei, tail); else sprintf(buf, "%s%s%s%s%s%"PRIu64"%s", div, div, div, div, div, n, tail); }
        else if (n < 100)           { if (danwei[0]) sprintf(buf, "%"PRIu64".%"PRIu64"%"PRIu64"%s%s"         , n, yu, yu2,      danwei, tail); else sprintf(buf, "%s%s%s%s%"PRIu64"%s"  , div, div, div, div, n, tail); }
        else if (n < 1000)          { if (danwei[0]) sprintf(buf, "%"PRIu64".%"PRIu64"%s%s"                  , n, yu          , danwei, tail); else sprintf(buf, "%s%s%s%"PRIu64"%s"    , div, div, div, n, tail); }
        else if (n < 10000)         { if (danwei[0]) sprintf(buf, "%s%"PRIu64"%s%s"                     ,div , n              , danwei, tail); else sprintf(buf, "%s%s%"PRIu64"%s"      , div, div, n, tail); }
        else if (n < 100000)        { if (danwei[0]) sprintf(buf, "%"PRIu64"%s%s"                            , n              , danwei, tail); else sprintf(buf, "%s%"PRIu64"%s"        , div, n, tail); }
    }
    return buf;
}

static inline char *int2human_2(int html_format, int left_align, uint64_t n, char *buf, int64_t rawnum, const char *tail)
{
    const char *div = html_format ? "&nbsp;" : " ";

    if (n < 10) {
        if (left_align > 0) {
            sprintf(buf, "%"PRIu64"%s%s", n, tail, div);
        } else {
            sprintf(buf, "%s%"PRIu64"%s", div, n, tail);
        }
        return buf; 
    }
    if (n < 100 || rawnum     ) { sprintf(buf, "%"PRIu64"%s"  , n              , tail); return buf; }
    if (n <               1000) { sprintf(buf, "k-%s"                          , tail); return buf; }
    if (n <              10000) { sprintf(buf, "%"PRIu64"k%s" , n/1000         , tail); return buf; }
    if (n <             100000) { sprintf(buf, "k+%s"                          , tail); return buf; }
    if (n <            1000000) { sprintf(buf, "m-%s"                          , tail); return buf; }
    if (n <           10000000) { sprintf(buf, "%"PRIu64"m%s" , n/1000000      , tail); return buf; }
    if (n <          100000000) { sprintf(buf, "m+%s"                          , tail); return buf; }
    if (n <         1000000000) { sprintf(buf, "g-%s"                          , tail); return buf; }
    if (n <        10000000000) { sprintf(buf, "%"PRIu64"g%s" , n/1000000000   , tail); return buf; }
    if (n <       100000000000) { sprintf(buf, "g+%s"                          , tail); return buf; }
    if (n <      1000000000000) { sprintf(buf, "t-%s"                          , tail); return buf; }
    if (n <     10000000000000) { sprintf(buf, "%"PRIu64"t%s" , n/1000000000000, tail); return buf; }
    if (n <    100000000000000) { sprintf(buf, "t+%s"                          , tail); return buf; }
    sprintf(buf, "BG");
    return buf;
}

static inline char *int2human_3(int html_format, int left_align, uint64_t n, char *buf, int64_t rawnum, const char *tail)
{
    const char *div = html_format ? "&nbsp;" : " ";

    if (left_align > 0) {
        if (n <                 10) { sprintf(buf, "%"PRIu64"%s%s%s", n, tail, div, div    ); return buf; }
        if (n <                100) { sprintf(buf, "%"PRIu64"%s%s"  , n, tail, div         ); return buf; }
        if (n < 1000 || rawnum    ) { sprintf(buf, "%"PRIu64"%s"      , n , tail             ); return buf; }
        if (n <              10000) { sprintf(buf, "%"PRIu64"k%s%s" , n/1000, tail, div    ); return buf; }
        if (n <             100000) { sprintf(buf, "%"PRIu64"k%s"   , n/1000, tail         ); return buf; }
        if (n <            1000000) { sprintf(buf, "1m-%s"          , tail                 ); return buf; }
        if (n <           10000000) { sprintf(buf, "%"PRIu64"m%s%s" , n/1000000, tail, div ); return buf; }
        if (n <          100000000) { sprintf(buf, "%"PRIu64"m%s"   , n/1000000, tail      ); return buf; }
        if (n <         1000000000) { sprintf(buf, "1G-%s"          , tail                 ); return buf; }
        if (n <        10000000000) { sprintf(buf, "%"PRIu64"g%s%s" , n/1000000000, tail, div); return buf; }
        if (n <       100000000000) { sprintf(buf, "%"PRIu64"g%s"   , n/1000000000, tail   ); return buf; }
        if (n <      1000000000000) { sprintf(buf, "1T-%s"          , tail                 ); return buf; }
        if (n <     10000000000000) { sprintf(buf, "%"PRIu64"t%s%s" , n/1000000000000, tail, div); return buf; }
        if (n <    100000000000000) { sprintf(buf, "%"PRIu64"t%s"   , n/1000000000000, tail); return buf; }
    } else {
        if (n <                 10) { sprintf(buf, "%s%s""%"PRIu64"%s", div, div, n , tail   ); return buf; }
        if (n <                100) { sprintf(buf, "%s""%"PRIu64"%s"  , div, n       , tail  ); return buf; }
        if (n < 1000 || rawnum    ) { sprintf(buf, "%"PRIu64"%s"      , n      , tail        ); return buf; }
        if (n <              10000) { sprintf(buf, "%s%"PRIu64"k%s" , div, n/1000 , tail   ); return buf; }
        if (n <             100000) { sprintf(buf, "%"PRIu64"k%s"   , n/1000     , tail    ); return buf; }
        if (n <            1000000) { sprintf(buf, "1m-%s"                      , tail     ); return buf; }
        if (n <           10000000) { sprintf(buf, "%s%"PRIu64"m%s" , div, n/1000000 , tail); return buf; }
        if (n <          100000000) { sprintf(buf, "%"PRIu64"m%s"   , n/1000000    , tail  ); return buf; }
        if (n <         1000000000) { sprintf(buf, "1G-%s"                      , tail     ); return buf; }
        if (n <        10000000000) { sprintf(buf, "%s%"PRIu64"g%s" , div, n/1000000000 , tail  ); return buf; }
        if (n <       100000000000) { sprintf(buf, "%"PRIu64"g%s"   , n/1000000000  , tail ); return buf; }
        if (n <      1000000000000) { sprintf(buf, "1T-%s"                        , tail   ); return buf; }
        if (n <     10000000000000) { sprintf(buf, "%s%"PRIu64"t%s" , div, n/1000000000000, tail); return buf; }
        if (n <    100000000000000) { sprintf(buf, "%"PRIu64"t%s"   , n/1000000000000, tail); return buf; }
    }
    sprintf(buf, "BIG");
    return buf;
}

static inline char *int2human_k(int64_t n, char *buf)
{
    if (n < 0) { buf[0] = '-'; buf++; n = -n; }
    n /= 1000;
    if (n < 1000 ) { sprintf(buf, "%"PRIu64"k", n); return buf; } n /= 1000;
    if (n < 1000 ) { sprintf(buf, "%"PRIu64"m", n); return buf; } n /= 1000;
    if (n < 1000 ) { sprintf(buf, "%"PRIu64"g", n); return buf; } n /= 1000;
    sprintf(buf, "%"PRIu64"t", n); return buf;
}
static inline char *int2human_4_k_noyu(int html_format, int left_align, int64_t n, char *buf, int64_t rawnum, const char *tail)
{
    if (n < 0) { buf[0] = '-'; buf++; n = -n; }
    if (rawnum > 0) { return int2dingchang_string_4_noyu(html_format, left_align, n, buf, "", tail); }

    n /= 1000;
    if (n < 1000 ) { int2dingchang_string_4_noyu(html_format, left_align, n, buf, "k", tail); return buf; } n /= 1000;
    if (n < 1000 ) { int2dingchang_string_4_noyu(html_format, left_align, n, buf, "m", tail); return buf; } n /= 1000;
    if (n < 1000 ) { int2dingchang_string_4_noyu(html_format, left_align, n, buf, "g", tail); return buf; } n /= 1000;
    int2dingchang_string_4_noyu(html_format, left_align, n, buf, "t", tail);
    return buf;
}

//buf size must >= 128
static inline char *int2human_filesize_k(int html_format, int64_t n, char *buf)
{
    buf[0] = 0;
    char tmpbuf[512] = "";
    int len = 0;
    if (n == 0) {
        strcpy(tmpbuf, "0k"); len = 2;
    } else {
        n /= 1000; if (n == 0) n = 1;
        if (n < 1000) {
            len = sprintf(tmpbuf, "%"PRIu64"k", n);
        } else if (n < 1000000) {
            len = sprintf(tmpbuf, "%"PRIu64",%03"PRIu64"k", n/1000, n%1000);
        } else if (n < 1000000000) {
            len = sprintf(tmpbuf, "%"PRIu64",%03"PRIu64",%03"PRIu64"k", n/1000000, (n%1000000)/1000, n%1000);
        } else if (n < 1000000000000) {
            len = sprintf(tmpbuf, "%"PRIu64",%03"PRIu64",%03"PRIu64",%03"PRIu64"k", n/1000000000, (n%10000000000)/1000, (n%1000000)/1000, n%1000);
        } else {
            len = sprintf(tmpbuf, "%"PRIu64"k", n);
        }
    }
    int i;
    for (i = len; i < 17; i++) {
        strcat(buf, html_format ? "&ensp;" : " ");
    }
    strcat(buf, tmpbuf);
    return buf;
}

static inline char *int2human_4_k(int html_format, int left_align, int64_t n, char *buf, int64_t rawnum, const char *tail)
{
    uint64_t yu;
    if (n < 0) { buf[0] = '-'; buf++; n = -n; }
    if (rawnum > 0) { return int2dingchang_string_4_yu(html_format, left_align, n, 0, buf, "", tail); }

    yu = n % 1000 / 100; n /= 1000;
    if (n < 1000 ) { int2dingchang_string_4_yu(html_format, left_align, n, yu, buf, "k", tail); return buf; } yu = n % 1000 / 100; n /= 1000;
    if (n < 1000 ) { int2dingchang_string_4_yu(html_format, left_align, n, yu, buf, "m", tail); return buf; } yu = n % 1000 / 100; n /= 1000;
    if (n < 1000 ) { int2dingchang_string_4_yu(html_format, left_align, n, yu, buf, "g", tail); return buf; } yu = n % 1000 / 100; n /= 1000;
    int2dingchang_string_4_yu(html_format, left_align, n, yu, buf, "t", tail);
    return buf;
}

static inline char *int2human_4(int html_format, int left_align, int64_t n, char *buf, int64_t rawnum, const char *tail)
{
    uint64_t yu;
    if (n < 0) { buf[0] = '-'; buf++; n = -n; }
    if (rawnum > 0) { return int2dingchang_string_4_yu(html_format, left_align, n, 0, buf, "", tail); }

    if (n <10000 ) { int2dingchang_string_4_yu(html_format, left_align, n, 0 , buf, "" , tail); return buf; } yu = n % 1000 / 100; n /= 1000;
    if (n < 1000 ) { int2dingchang_string_4_yu(html_format, left_align, n, yu, buf, "k", tail); return buf; } yu = n % 1000 / 100; n /= 1000;
    if (n < 1000 ) { int2dingchang_string_4_yu(html_format, left_align, n, yu, buf, "m", tail); return buf; } yu = n % 1000 / 100; n /= 1000;
    if (n < 1000 ) { int2dingchang_string_4_yu(html_format, left_align, n, yu, buf, "g", tail); return buf; } yu = n % 1000 / 100; n /= 1000;
    int2dingchang_string_4_yu(html_format, left_align, n, yu, buf, "t", tail);
    return buf;
}

static inline char *int2human_5(int html_format, int left_align, int64_t n, char *buf, int64_t rawnum, const char *tail)
{
    uint64_t yu, yu2;
    if (n < 0) { buf[0] = '-'; buf++; n = -n; }
    if (rawnum > 0) { return int2dingchang_string_5_yu(html_format, left_align, n, 0, 0, buf, "", tail); }

    if (n <10000 ) { int2dingchang_string_5_yu(html_format, left_align, n, 0 , 0  , buf, "" , tail); return buf; } yu = n % 1000 / 100; yu2 = n % 100 / 10; n /= 1000;
    if (n < 1000 ) { int2dingchang_string_5_yu(html_format, left_align, n, yu, yu2, buf, "k", tail); return buf; } yu = n % 1000 / 100; yu2 = n % 100 / 10; n /= 1000;
    if (n < 1000 ) { int2dingchang_string_5_yu(html_format, left_align, n, yu, yu2, buf, "m", tail); return buf; } yu = n % 1000 / 100; yu2 = n % 100 / 10; n /= 1000;
    if (n < 1000 ) { int2dingchang_string_5_yu(html_format, left_align, n, yu, yu2, buf, "g", tail); return buf; } yu = n % 1000 / 100; yu2 = n % 100 / 10; n /= 1000;
    int2dingchang_string_5_yu(html_format, left_align, n, yu, yu2, buf, "t", tail);
    return buf;
}
#define int2human int2human_5

static inline char *int2human_6(int html_format, int left_align, int64_t n, char *buf, int64_t rawnum, const char *tail)
{
    uint64_t yu, yu2, yu3;
    if (n < 0) { buf[0] = '-'; buf++; n = -n; }
    if (rawnum > 0) { return int2dingchang_string_6_yu(html_format, left_align, n, 0, 0, 0, buf, "", tail); }

    if (n <10000 ) { int2dingchang_string_6_yu(html_format, left_align, n, 0 , 0  , 0  , buf, "" , tail); return buf; } yu = n % 1000 / 100; yu2 = n % 100 / 10; yu3 = n % 10; n /= 1000;
    if (n < 1000 ) { int2dingchang_string_6_yu(html_format, left_align, n, yu, yu2, yu3, buf, "k", tail); return buf; } yu = n % 1000 / 100; yu2 = n % 100 / 10; yu3 = n % 10; n /= 1000;
    if (n < 1000 ) { int2dingchang_string_6_yu(html_format, left_align, n, yu, yu2, yu3, buf, "m", tail); return buf; } yu = n % 1000 / 100; yu2 = n % 100 / 10; yu3 = n % 10; n /= 1000;
    if (n < 1000 ) { int2dingchang_string_6_yu(html_format, left_align, n, yu, yu2, yu3, buf, "g", tail); return buf; } yu = n % 1000 / 100; yu2 = n % 100 / 10; yu3 = n % 10; n /= 1000;
    int2dingchang_string_6_yu(html_format, left_align, n, yu, yu2, yu3, buf, "t", tail);
    return buf;
}

#define str2align(html_format, left_align, str, str_len, buf, buf_len, to_len, cut) ({ \
    int _total_byte = 0; \
    do { \
        const char *_div = html_format ? "_" : " "; \
        int _padding; \
        int _total_html_len = 0; \
        int _str_len = str_len; \
        int _buf_len = buf_len; \
        int _to_len = to_len; \
        if (left_align <= 0) { \
            if (_to_len > (_str_len)) { \
                if (html_format) { \
                    if (_total_byte +    strlen("<span style=\"color:hsla(9, 100%, 64%, 0);\">") >= _buf_len) { LOGFEW("buf too small\n"); break; } \
                    memcpy((buf) + _total_byte, "<span style=\"color:hsla(9, 100%, 64%, 0);\">", strlen("<span style=\"color:hsla(9, 100%, 64%, 0);\">")); \
                    _total_byte +=                                                               strlen("<span style=\"color:hsla(9, 100%, 64%, 0);\">"); \
                } \
                for (_padding = _to_len - (_str_len); _padding > 0; _padding--) { \
                    if (_total_byte + 1 >= _buf_len) { LOGFEW("buf too small\n"); break; } \
                    memcpy((buf) + _total_byte, _div, 1); \
                    _total_byte += 1; \
                    _total_html_len++; \
                    if (cut && _total_html_len >= _to_len) break; \
                } \
                if (html_format) { \
                    if (_total_byte +    strlen("</span>") >= _buf_len) { LOGFEW("buf too small\n"); break; } \
                    memcpy((buf) + _total_byte, "</span>", strlen("</span>")); \
                    _total_byte +=                         strlen("</span>"); \
                } \
            } \
        } \
        if (cut) { \
            int can_add = _to_len - _total_html_len; \
            if ((_str_len) > can_add) { \
                int cut_len = (_str_len) - can_add; \
                if (cut == 1) { \
                    if (_total_byte + can_add >= _buf_len) { LOGFEW("buf to small\n"); (buf)[_total_byte] = 0; break; } \
                    if (can_add >= 3) { \
                        can_add -= 3; \
                        cut_len += 3; \
                        memcpy((buf) + _total_byte, "...", 3); \
                        _total_byte += 3; \
                        _total_html_len += 3; \
                    } \
                    memcpy((buf) + _total_byte, (str) + cut_len, can_add); \
                    _total_byte += can_add; \
                    _total_html_len += can_add; \
                } else { \
                    if (_total_byte + can_add >= _buf_len) { LOGFEW("buf to small\n"); (buf)[_total_byte] = 0; break; } \
                    memcpy((buf) + _total_byte, (str), can_add); \
                    _total_byte += can_add; \
                    _total_html_len += can_add; \
                    if (can_add >= 3) { \
                        memcpy((buf) + _total_byte - 3, "...", 3); \
                    } \
                } \
            } else { \
                if (_total_byte + (_str_len) >= _buf_len) { LOGFEW("buf to small\n"); (buf)[_total_byte] = 0; break;} \
                memcpy((buf) + _total_byte, (str), (_str_len)); \
                _total_byte += (_str_len); \
                _total_html_len += (_str_len); \
            } \
        } else { \
            if (_total_byte + (_str_len) >= _buf_len) { LOGFEW("buf to small, _str_len %d, buf_size %d, to_len %d str [%.*s]\n", (_str_len), _buf_len, _to_len, (_str_len), (str)); (buf)[_total_byte] = 0; break; } \
            memcpy((buf) + _total_byte, (str), (_str_len)); \
            _total_byte += (_str_len); \
            _total_html_len += (_str_len); \
        } \
        if (left_align > 0) { \
            if (_to_len > (_str_len)) { \
                if (html_format) { \
                    if (_total_byte +    strlen("<span style=\"color:hsla(9, 100%, 64%, 0);\">") >= _buf_len) { LOGFEW("buf too small\n"); break; } \
                    memcpy((buf) + _total_byte, "<span style=\"color:hsla(9, 100%, 64%, 0);\">", strlen("<span style=\"color:hsla(9, 100%, 64%, 0);\">")); \
                    _total_byte +=                                                               strlen("<span style=\"color:hsla(9, 100%, 64%, 0);\">"); \
                } \
                for (_padding = _to_len - (_str_len); _padding > 0; _padding--) { \
                    if (_total_byte + 1 >= _buf_len) { LOGFEW("buf too small\n"); break; } \
                    memcpy((buf) + _total_byte, _div, 1); \
                    _total_byte += 1; \
                    _total_html_len++; \
                } \
                if (html_format) { \
                    if (_total_byte +    strlen("</span>") >= _buf_len) { LOGFEW("buf too small\n"); break; } \
                    memcpy((buf) + _total_byte, "</span>", strlen("</span>")); \
                    _total_byte +=                       strlen("</span>"); \
                } \
            } \
        } \
    } while (0); \
    (buf)[_total_byte] = 0; \
    (buf); })

#endif
